{extend name="layout/tpl" /}

{block name="title"}菜单添加{/block}

{block name="content"}
<form class="layui-form" action="">
    {if condition="empty($pid)"}
    <div class="layui-form-item">
        <label class="layui-form-label">菜单:</label>
        <div class="layui-input-inline">
            <input type="text" name="menu" lay-verify="menu" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
            <input type="hidden" name="parent" value="0">
        </div>
    </div>
    {else}
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单:</label>
        <div class="layui-input-inline">
            <select name="parent">{foreach $tree as $tr}<option value="{$tr.id}" {if condition="$tr.id==$pid"}selected{/if}>{$tr.title}</option>{/foreach}</select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">子菜单:</label>
        <div class="layui-input-inline">
            <input type="text" name="menu" lay-verify="menu" autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
        </div>
    </div>
    {/if}

    <div class="layui-form-item">
        <label class="layui-form-label">路径:</label>
        <div class="layui-input-inline">
            <input type="text" name="path" lay-verify="path" autocomplete="off" placeholder="请输入小写的访问路径" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">序号:</label>
        <div class="layui-input-inline">
            <input type="text" name="num" lay-verify="number" placeholder="数字越小越靠前" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态:</label>
        <div class="layui-input-inline">
            <input type="radio" name="status" value="1" title="显示" checked="">
            <input type="radio" name="status" value="0" title="隐藏">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="footerjs"}
<script>
    layui.use('table', function(){
        var form = layui.form;
        form.verify({
            menu: function (value) {
                if(value.length < 1) {
                    return '菜单名称必填';
                }
            }
        });
        form.on('submit(submit)',function(data){
            var index;
            $.ajax({
                type:       'post',
                data:       data.field,
                dataType:   'json',
                beforeSend: function () {
                    index = layer.load(0, {shade: false});
                },
                success:    function (msg) {
                    layer.close(index);
                    if(msg.errCode === "0") {
                        parent.location.reload();
                    } else {
                        layer.msg(msg.msg);
                    }
                }
            });
            return false;   // 阻止表单跳转
        });
    });
</script>
{/block}